﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Assignment_3.Classes;

namespace Assignment_3.Feature___Users
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["username"] != null)
            {
                Response.Redirect("~/Feature - Users/Logout.aspx");
            }
        }

        protected void loginBtn_Click(object sender, EventArgs e)
        {
            foreach (UserAccount x in DatabaseManager.GetAllUserAccounts())
            {
                if (x.Username.Equals(tbxLoginUsername.Text) && x.Password.Equals(tbxLoginPassword.Text))
                {
                    Session["username"] = x.Username;
                    Session["usertype"] = x.UserType;
                    Response.Redirect("~/Feature - Reports/OverviewReport.aspx");
                }
            }

            lblLoginError.Visible = true;
        }
    }
}